<template name="asnReceiveRFPalletInputPage">
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true" backRouterName="asnReceiveRFListPage">
			<block slot="content">托盘号扫描</block>
		</cu-custom>
		<form>
			<u-toast ref="uToast"></u-toast>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.1s'}]">
				<view class="title">ASN：</view>{{this.myFormData.asnCode}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.2s'}]">
				<view class="title">外部单号：</view>{{this.myFormData.customerBill}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.3s'}]">
				<view class="title">已收数量/总量：</view>{{this.myFormData.recived}}/{{this.myFormData.totalQty}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.4s'}]">
				<view class="title">收货库位：</view>{{this.myFormData.receiveLoc}}
			</view>
			<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.5s'}]">
				<view class="title">托盘号：</view>
				<input placeholder="请输入托盘号" name="input" v-model="myFormData.palletNo" @confirm="onSubmit"></input>
				<text class="cuIcon-scan" @click="InputFocus"></text>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-blue lg"  @click="onSubmit">确认</button>
			</view>
		</form>
	</view>
</template>

<script>
	import crypto from '@/api/crypto.js' 
	export default {
		data() {
			return {
				myFormData:{
					asnId:'',
					asnCode:'',
					customerBill:'',
					receiveLoc:'',
					totalQty:0,
					recived:0,
					palletNo:'',
					beNewPallet:false,
				},
				palletNoScanUrl:'/pda/palletNoScan',
				changePalletNoUrl:'/pda/changeNewPallet',
			};
		},
		onLoad: function (option) {
			if(!option.item){
				uni.navigateTo({
					url: '/pages/wms/asnReceiveRFListPage'
				});
			}
			const tempItem = JSON.parse(decodeURIComponent(option.item));
			this.myFormData = tempItem 
			if(this.myFormData.beNewPallet){
				//重新加载数据
				this.$http.get(this.changePalletNoUrl,{params:{asnId:crypto.encrypt(this.myFormData.asnId)}}).then(res=>{
				  if(res.data.success){
					  this.myFormData = res.data.result;
				  }else{
					 this.$refs.uToast.show({
					 		type: 'error',
					 		message: res.data.message,
					 })
				  }
				}).catch(()=>{
					this.$tip.loaded();
				});
			}
		},
		methods: {
			onSubmit() {
				if(!this.myFormData.palletNo){
					this.$refs.uToast.show({
							type: 'error',
							message: "请扫描收货托盘号!",
					})
					return;
				}
				uni.navigateTo({
					url: '/pages/wms/asnReceiveRFDetailListPage?item='+ encodeURIComponent(JSON.stringify(this.myFormData))
				});
			},
			InputFocus() {
				 let that = this;
				 // 调起条码扫描
				 uni.scanCode({
					 onlyFromCamera: true,
					 success: function (res) {
						 that.myFormData.palletNo = res.result
					 }
				 });
			},
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>
